<?php
    use User\Model\EditorModel;
?>
<style>
	.table>tbody>tr>td{vertical-align: middle}
	.modal-dialog{width:380px;}
	.modal-content{background-color: transparent}
	iframe{background-color:white}
	.q-image{top:180px;left:450px;position:absolute}
	.apple_left{float:left;}
	.apple_right{float:right}
	.apple_bottom{position:absolute;top:580px;left:18px}
</style>
<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">H5 编辑器</h1>
		</div>
		<!-- /.col-lg-12 -->
	</div>

	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<!--<a style="margin-left:7px" href="{:U('User/Editor/edit')}" class="btn btn-success">新增</a>-->
					<div class="btn-group">
						<button data-toggle="dropdown" class="btn btn-success dropdown-toggle" type="button" id="btnGroupDrop1">
							新增  <span class="caret"></span>
						</button>
						<ul aria-labelledby="btnGroupDrop1" role="menu" class="dropdown-menu">
							<li><a href="{:U('User/Editor/edit')}">老版编辑器</a></li>
							<li><a href="{:U('User/Editor/new_edit')}">新版编辑器</a></li>
						</ul>
					</div>
					<a href="javascript:;" id="deleteAll" class="btn btn-danger">删除</a>
				</div>
				<!-- /.panel-heading -->

				<div class="panel-body">
					<div class="col-lg-12">
						<div class="table-responsive">
							<table class="table">
								<thead>
								<tr>
									<th><input type="checkbox" id="selectAll"></th>
									<th>编号</th>
									<th style="width:200px">标题</th>
									<th>链接地址</th>
									<th>关键词</th>
									<th>创建时间</th>
									<th class="textAlignCenter">操作</th>
								</tr>
								</thead>
								<tbody>
								<volist name="list" id="item">
									<tr>
										<td><input type="checkbox" name="ids" value="{$item.id}"></td>
										<td>{$item.id}</td>
										<td>{$item.title}</td>
										<td>{$item.link}</td>
										<td>{$item.keyword}</td>
										<td>{$item.createdate}</td>
										<td>
											<button onclick="preview({$item[id]}, '{$item[link]}')" title="预览" class="btn btn-info">预览</button>
											<if condition="$item.reserve eq EditorModel::EDITOR_VERSION2">
												<a href="{:U('User/Editor/new_edit', array('id'=>$item['id']))}" title="编辑页面" class="btn btn-default"><i class="fa fa-edit"></i></a>
											<else/>
												<a href="{:U('User/Editor/edit', array('id'=>$item['id']))}" title="编辑页面" class="btn btn-default"><i class="fa fa-edit"></i></a>
											</if>
											<a href="javascript:;" title="删除页面" onclick="return deleteItem({$item['id']});" class="btn btn-default"><i class="fa fa-times"></i></a>
										</td>
									</tr>
								</volist>
								</tbody>
							</table>


						</div>
						<!-- /.table-responsive -->

						<div class="pages">
							{$page}
						</div>
					</div>
					<!-- / .col-lg-12 -->
				</div>
				<!-- / .panel-body -->
			</div>
			<!-- /.panel-body -->
		</div>
		<!-- /.panel -->
	</div>
	<!-- /.col-lg-12 -->
</div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="preview" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<img class="apple_top" src="/Public/images/apple_top.png" width="380">
			<img class="apple_left" src="/Public/images/apple_left.png" height="590">
			<iframe src="" id="preview_content" allowTransparency="true" width="334" height="485" scrolling="yes" frameborder="0">
			</iframe>
			<img class="apple_right" src="/Public/images/apple_right.png" height="590">
			<img class="apple_bottom" src="/Public/images/apple_bottom.png" width="345">
		</div>
		<div class="q-image"><img src="" id="qrcode"></div>
	</div>
</div>
<script>
	function preview(id, link){
	    var qrcode_url = '/User/Editor/getQrcode?id='+id;
        $('#preview').modal('show');
	    $("#preview_content").attr("src", link);
        $("#qrcode").attr("src", qrcode_url);
	}

    //清除弹窗原数据
    $("#preview").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
        $("#preview_content").attr("src", "");
    });

    $("#selectAll").click(function(){
        if($(this).prop('checked') == true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    })

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids != ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/Editor/deletes',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请勾选页面！');
		}
    });

    function deleteItem(id){
		if(!confirm('确认删除吗？')) return false;
        $.ajax({
            data: {id: id},
            dataType: 'json',
            url: '/User/Editor/delete',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }
</script>